<%@page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%
	String path = request.getContextPath();
%>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
	<script language="javascript" type="text/javascript" src="<%=path%>/js/validatorTool.js"></script>
	
    <script language="javascript" type="text/javascript">
		//全选
    	function ChkAllClick(sonName, cbAllId){
    		var arrSon = document.getElementsByName(sonName);
    	 	var cbAll = document.getElementById(cbAllId);
    	 	var tempState=cbAll.checked;
    	 	for(i=0;i<arrSon.length;i++) {
    	  		if(arrSon[i].checked!=tempState){
    	        	arrSon[i].click();
    	 		}
    		}
    	}
    	
    	//合同接受
    	function acceptContract(){
	    	var checkArr = document.getElementsByName("checkBoxComp");
        	var row=0;
        	for(i=0;i<checkArr.length;i++) {
        		if(checkArr[i].checked){
	        		var contractPk = checkArr[i].id;
	    	  		var status=trimStr(document.getElementById("status_"+contractPk).value);
	    	  		
	    	  		if(status==1 ){
	    	  			row=row+1;
						// 设置页面状态
		  				var confirmStatus = document.getElementById("status_"+contractPk);
			        	confirmStatus.value = 2;
	    	  		}else if(status ==2 || status == 3){
	    	  			alert("存在已经确认的合同，请重新选择!");
						return;
	    	  		}
    	  		}
    		}
    		if(row==0){
				alert("请选择响应状态为\"待确认\"的合同！");
				return ;
    		}
		    form2.action="<%=path%>/contract/acceptContracts";
			form2.submit();
    		
		}

		//合同拒绝
		function rejectContract() {
			var checkArr = document.getElementsByName("checkBoxComp");
        	var row=0;
        	for(i=0;i<checkArr.length;i++) {
    	  		if(checkArr[i].checked){
    	  			var contractPk=checkArr[i].id;
        	  		var status=trimStr(document.getElementById("status_"+contractPk).value);
        	  		if(status==1){
        	  			row++;
        	  		}else if(status ==2 || status == 3){
	    	  			alert("存在已经确认的合同，请重新选择!");
						return;
	    	  		}
    	 		}
    		}
    		if(row==0){
				alert("请选择响应状态为\"待确认\"的合同！");
				return ;
    		}else{
        		var rejectReason=prompt("请输入拒绝原因：","");
        		if(trimStr(rejectReason)==null || trimStr(rejectReason)==""){
					alert("拒绝，必须输入拒绝原因。");
					return ;
            	}else{
	  				document.getElementById("rejectReason").value=rejectReason;
		        	form2.action="<%=path%>/contract/rejectContracts";
		        	form2.submit();
    			}
        	}
		}
</script>
</head>
<body class="fullbody">
            <div class="context">
                <div class="position">
                    <div class="tposi">当前位置：
                        <a href="javascript:changeMenu(1,'<%=path%>/infopub/pubmain?menuid=1');"class="linkstyle">首页</a>&nbsp;&gt;&gt;&nbsp;
                   		 <a href="javascript:changeMenu(3,'');" class="linkstyle">我的订单\合同</a>&nbsp;&gt;&gt;&nbsp;
                        <span class="curposition">合同确认</span>
                    </div>
                    <div class="help">
						<a href="javascript:void(null);" onclick="doHelp('<%=request.getContextPath()%>/help/html/HTQR.html');" class="linkstyle">帮助</a>
					</div>    
                </div>
                <div class="margin8"></div>
                <div class="subpage_title">
                    <div class="title_index">
                        <img src="<%=path%>/images/common/dot03.gif" alt="" border="0" />&nbsp;合同确认</div>
                </div>
                <div class="margin20"></div>
                <div class="subpage_bidlist">
                    <div class="subpage_search" >
                    	<form name="form1" action="<%=path%>/contract/qryContractConfirm" method="post">
	                        <table border="0" cellpadding="0" cellspacing="0" class="searchtable">
	                            <tr>
	                                <td valign="middle" class="w_1">合同编号：</td>
	                                <td valign="middle" class="w_2">
	                                    <input id="qryCtNo" name="qryCtNo" type="text"  value="${qryCtNo}"  class="searchtext" />
	                                </td>
	                                <td valign="middle" class="w_1">合同名称：</td>
	                                <td valign="middle" class="w_2">
	                                    <input id="qryCtName" name="qryCtName" type="text" value="${qryCtName}" class="searchtext" />
	                                </td>
	                            </tr>
	                            
	                            <tr>
	                            	<td valign="middle" class="w_1">版本号：</td>
	                                <td valign="middle" class="w_2">
	                                    <input id="qryVersion" name="qryVersion" type="text"  value="${qryVersion}"  class="searchtext" />
	                                </td>
	                                <td valign="middle" class="w_1">合同签定日期：</td>
	                                <td valign="middle" class="w_2">
	                                    <input id="qryCtSignBDate" name="qryCtSignBDate" type="text" 
	                                    	onclick="return showCalendar('qryCtSignBDate', 'y-mm-dd');"   
	                                    	value="${qryCtSignBDate}" class="searchdate" readonly="readonly"/>&nbsp;至&nbsp;
	                                    <input id="qryCtSignEDate" name="qryCtSignEDate" type="text" 
	                                    	onclick="return showCalendar('qryCtSignEDate', 'y-mm-dd');" 
		                                    value="${qryCtSignEDate}" class="searchdate" readonly="readonly"/>
	                                </td>
	                            </tr>
	                            <tr>
	                               <td valign="middle" class="w_1"> 响应状态：</td>
	                               <td valign="middle" class="w_2"><select class="searchtext"
										name="qryconfirmStatus" id="qryconfirmStatus">
										<option value="">全部</option>
										<option value="1"
											<c:if test="${1==qryconfirmStatus}">selected</c:if>>待确认</option>
										<option value="2"
											<c:if test="${2==qryconfirmStatus}">selected</c:if>>接受</option>
										<option value="3"
											<c:if test="${3==qryconfirmStatus}">selected</c:if>>拒绝</option>
									</select></td>
	                            </tr>
	                            <tr><td colspan="4">&nbsp;</td></tr>
	                            <tr>
	                                <td valign="middle" colspan="4" align="center">
	                                    <input type="submit" class="btnscs" value="查询" />&nbsp;&nbsp;&nbsp;&nbsp;   
	                                    <input type="button" class="btnscs" value="取消" onclick="resetData()"/>&nbsp;&nbsp;
	                                </td>
	                            </tr>
	                        </table>
                        </form>
                    </div>
                    <div class="margin20">
                    </div>
                    <div>
                    <form name="form2"  method="post">
						<input type="hidden" value="" name="rejectReason" id="rejectReason" />
                        <table class="tableCss" cellpadding="0" cellspacing="0">
                            <tr class="titleTr">
                            	<th width="35px">
									<input type="checkbox" name="chkAll" id="chkAll" onclick="ChkAllClick('checkBoxComp','chkAll')" />
								</th>
                                <th width="136px">合同编号</th>
                                <th width="180px">合同名称</th>
                                <th width="75px">版本号 </th>
                                <th width="117px">合同签定日期</th>
                                <th width="116px">计划生效日期</th>
                                <th width="116px" class="th1">计划失效日期</th>
                                <th width="60px">响应状态</th>
                            </tr>
                            <c:if test="${qryResForm!=null}"> 
								<c:forEach items="${qryResForm}" var="ctForm" varStatus="index">
									<c:if test="${ctForm.index % 2==1}">
										<tr align="left" class="contTr-old"  >
									</c:if>
									<c:if test="${ctForm.index % 2==0}">
										<tr align="left" class="contTr-even">
									</c:if>
									<td class="td1">
										<input type="checkbox" id="${ctForm.pkContract}" name="checkBoxComp"  value="${ctForm.pkContract}_${ctForm.ts}_${ctForm.confirmStatus}"/> 
										<input type="hidden" id="status_${ctForm.pkContract}" name="confirmStatus" value="${ctForm.confirmStatus}"/> 
									</td>
									<td class="td1"><a href="<%=path%>/contract/contractDetail?ctpk=${ctForm.pkContract}&isConfirm=Y">${ctForm.billNo}</a></td>
									<td class="td1">${ctForm.ctName}</td>
									<td class="td1">${ctForm.versionNo}</td>
									<td class="td1">${ctForm.ctSignDate}</td>
									<td class="td1">${ctForm.ctValiddate}</td>
									<td class="td1">${ctForm.ctInvalidate}</td>
									<td class="td1">
										<c:if test="${1==ctForm.confirmStatus}">待确认</c:if>
										<c:if test="${2==ctForm.confirmStatus}">接受</c:if>
										<c:if test="${3==ctForm.confirmStatus}">拒绝</c:if>
									</td>
									</tr>
								</c:forEach>
							</c:if>
                        </table>
                       </form>
                    </div>
                    <div class="margin8"></div>
                    <div>
						<table width="600" align="center" border="0" cellspacing="0"
							cellpadding="0">
							<tr id="contract_confirm" align="center">
								<td><input type="button" class="btnscs" value="接受"
									onclick="acceptContract()" /> &nbsp;&nbsp;&nbsp;&nbsp; <input
									type="button" class="btnscs" value="拒绝" onclick="rejectContract()" />
								&nbsp;&nbsp;&nbsp;&nbsp; 
								</td>
							</tr>
						</table>
					</div>
                    <div class="margin8">
                    	<table align="left">
							<tr class="title">
								<td>
									<div id="message" class="msgcolor">${system_err_msg}</div>
								</td>
							</tr>
						</table>
					</div> 
                </div>
            </div>
        <div class="margin20"></div>
</body>
</html>